package helper

import (
	"strings"

	"github.com/fatih/structs"
)

type tools struct{}

func (t *tools) StrcuctToMap(query interface{}) string {
	var queryStrList []string
	result := structs.Map(query)
	if result == nil {
		return ""
	}
	for k, v := range result {
		queryStrList = append(queryStrList, k+"="+v.(string))
	}
	str := strings.Join(queryStrList, "&")[1:]
	return "?" + str
}

// Tools 工具型结构体
var Tools = tools{}
